package registnet.records.source;

import registnet.records.Grade;
import registnet.records.ICourse;
import registnet.records.Section;
import registnet.records.Student;

public class GradeSource {

	private Student student;
	private ICourse course;
	private int semester;
	private int year;
	private double gradeReceived;
	private Grade grade;
	
	
	/**
	 * Default constructor
	 * 
	 * @param student - The student who obtained the grade
	 * @param course - The course in which the grade was obtained
	 * @param semester - The semeter when the grade was obtained
	 * @param year - The year when the grade was obtained
	 * @param gradeReceived - The grade received
	 */
	public GradeSource(Student student, ICourse course, int semester, int year, double gradeReceived){
		this.student = student;
		this.course = course;
		this.semester = semester;
		this.year = year;
		this.gradeReceived = gradeReceived;
		this.load();
	}

	
	/**
	 * Loads data from source
	 */
	public void load(){
		try{
			registnet.dao.Course DAOCourse = new registnet.dao.CoursePeer().getCourse(this.course.getCourseCode());
			registnet.dao.Student DAOStudent = new registnet.dao.StudentPeer().getStudent(this.student.getStudentNumber());
			registnet.dao.Grade DAOGrade = new registnet.dao.GradePeer().getGrade(DAOCourse.getCourseId(), DAOStudent.getStudentId(), this.semester, this.year, this.gradeReceived);
			Section section = new SectionSource(this.course, DAOGrade.getSectionName()).getSection();
			this.grade = new Grade(this.student, this.course, this.gradeReceived);
			this.grade.setCredit(DAOGrade.getCredit());
			this.grade.setRemarks(DAOGrade.getRemarks());
			this.grade.setSection(section);
			this.grade.setSemester(this.semester);
			this.grade.setYear(this.year);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	/**
	 * Gets the grade
	 * 
	 * @return The grade
	 */
	public Grade getGrade(){
		return this.grade;
	}
	
}